home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-05 / drivers2.zip / NE1000.ASM < prev    next >
Assembly Source File  |  1992-01-10  |  7KB  |  275 lines

  1. version    equ    5
  2. ;History:54,1
  3.  
  4. ;  The following people have contributed to this code: David Horne, Eric
  5. ;  Henderson, and Bob Clements.
  6.  
  7. ;  Copyright, 1988-1992, Russell Nelson, Crynwr Software
  8.  
  9. ;   This program is free software; you can redistribute it and/or modify
  10. ;   it under the terms of the GNU General Public License as published by
  11. ;   the Free Software Foundation, version 1.
  12. ;
  13. ;   This program is distributed in the hope that it will be useful,
  14. ;   but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. ;   GNU General Public License for more details.
  17. ;
  18. ;   You should have received a copy of the GNU General Public License
  19. ;   along with this program; if not, write to the Free Software
  20. ;   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.  
  23.     include    defs.asm
  24.  
  25. code    segment    word public
  26.     assume    cs:code, ds:code
  27.  
  28. ;*****************************************************************************
  29. ;
  30. ;    NE1000 controller board offsets
  31. ;    IO port definition (BASE in io_addr)
  32. ;*****************************************************************************
  33. NE_DATAPORT    EQU    10h        ; NE1000 Port Window.
  34. NE_RESET    EQU    1fh        ; Issue a read for reset
  35. EN_OFF        equ    0h
  36.  
  37.     include    8390.inc
  38.  
  39. ; Shared memory management parameters
  40.  
  41. SM_TSTART_PG    EQU    20h        ; First page of TX buffer
  42. SM_RSTART_PG    EQU    26h        ; start at page 26
  43. SM_RSTOP_PG    EQU    40h        ; end at page 40
  44.  
  45. ram_enable    macro
  46.     endm
  47.  
  48. reset_8390    macro
  49.     loadport
  50.     setport    NE_RESET
  51.     in    al,dx
  52.     longpause
  53.     out    dx,al        ; should set command 21, 80
  54.     endm
  55.  
  56. terminate_board    macro
  57.     endm
  58.  
  59.     public    int_no, io_addr
  60. int_no        db    3,0,0,0        ;must be four bytes long for get_number.
  61. io_addr        dw    0300h,0        ; I/O address for card (jumpers)
  62.  
  63.     public    driver_class, driver_type, driver_name, driver_function, parameter_list
  64. driver_class    db    BLUEBOOK, IEEE8023, 0        ;from the packet spec
  65. driver_type    dw    53        ;from the packet spec
  66. driver_name    db    'NE1000',0    ;name of the driver.
  67. driver_function    db    2
  68. parameter_list    label    byte
  69.     db    1    ;major rev of packet driver
  70.     db    9    ;minor rev of packet driver
  71.     db    14    ;length of parameter list
  72.     db    EADDR_LEN    ;length of MAC-layer address
  73.     dw    GIANT    ;MTU, including MAC headers
  74.     dw    MAX_MULTICAST * EADDR_LEN    ;buffer size of multicast addrs
  75.     dw    0    ;(# of back-to-back MTU rcvs) - 1
  76.     dw    0    ;(# of successive xmits) - 1
  77. int_num    dw    0    ;Interrupt # to hook for post-EOI
  78.             ;processing, 0 == none,
  79.  
  80. is_186        db    0
  81.  
  82. ;
  83. ;    Special case Block input routine. Used on extra memory
  84. ;    space for board ID etc. DMA count is set X2,
  85. ;    CX = byte count, es:si = buffer location, ax = buffer address
  86. ;
  87. sp_block_input:
  88. ;    Nothing special needed for NE-1000.
  89. ;
  90. ;    Block input routine
  91. ;    CX = byte count, es:di = buffer location, ax = buffer address
  92.  
  93.     public    block_input
  94. block_input:
  95.     push    ax        ; save buffer address
  96.     loadport
  97.     setport EN_CCMD
  98.     pause_
  99.     mov    al,ENC_NODMA+ENC_PAGE0+ENC_START
  100.     out    dx,al
  101.     mov    ax,cx            ;get the count to be output.
  102.     setport    EN0_RCNTLO    ; remote byte count 0
  103.     pause_
  104.     out    dx,al
  105.     setport    EN0_RCNTHI
  106.     pause_
  107.     mov    al,ah
  108.     out    dx,al
  109.     pop    ax        ; get our page back
  110.     setport    EN0_RSARLO
  111.     pause_
  112.     out    dx,al        ; set as hi address
  113.     setport    EN0_RSARHI
  114.     pause_
  115.     mov    al,ah
  116.     out    dx,al
  117.     setport EN_CCMD
  118.     pause_
  119.     mov    al,ENC_RREAD+ENC_START    ; read and start
  120.     out    dx,al
  121.     setport    NE_DATAPORT
  122.     pause_
  123.     cmp    is_186,0
  124.     jnz    read_186
  125. read_loop:
  126.     in    al,dx        ; get a byte
  127.     stosb            ; save it
  128.     loop    read_loop
  129.     ret
  130. read_186:
  131.     db    0f3h, 06ch    ;masm 4.0 doesn't grok "rep insb"
  132.     ret
  133. ;
  134. ;    Block output routine
  135. ;    CX = byte count, ds:si = buffer location, ax = buffer address
  136.  
  137. block_output:
  138.     assume    ds:nothing
  139.     push    ax        ; save buffer address
  140.     inc    cx        ; make even
  141.     and    cx,0fffeh
  142.     loadport
  143.     setport EN_CCMD
  144.     pause_
  145.     mov    al,ENC_NODMA+ENC_START
  146.     out    dx,al        ; stop & clear the chip
  147.     setport    EN0_RCNTLO    ; remote byte count 0
  148.     pause_
  149.     mov    al,cl
  150.     out    dx,al
  151.     setport    EN0_RCNTHI
  152.     pause_
  153.     mov    al,ch
  154.     out    dx,al
  155.     pop    ax        ; get our page back
  156.     setport    EN0_RSARLO
  157.     pause_
  158.     out    dx,al        ; set as lo address
  159.     setport    EN0_RSARHI
  160.     pause_
  161.     mov    al,ah
  162.     out    dx,al
  163.     setport EN_CCMD
  164.     pause_
  165.     mov    al,ENC_RWRITE+ENC_START    ; write and start
  166.     out    dx,al
  167.     setport    NE_DATAPORT
  168.     pause_
  169.     cmp    byte ptr is_186,0
  170.     jnz    write_186
  171. write_loop:
  172.     lodsb            ; get a byte
  173.     out    dx,al        ; save it
  174.     loop    write_loop
  175.     jmp    short block_output_1
  176. write_186:
  177.     db    0f3h, 06eh    ;masm 4.0 doesn't grok "rep outsb"
  178. block_output_1:
  179.     mov    cx,0
  180.     setport    EN0_ISR
  181. tx_check_rdc:
  182.     in    al,dx
  183.     test    al,ENISR_RDC    ; dma done ???
  184.     jnz    tx_start
  185.     loop    tx_check_rdc
  186.     stc
  187.     ret
  188. tx_start:
  189.     clc
  190.     ret
  191.  
  192.  
  193.     include    8390.asm
  194.  
  195.     public    usage_msg
  196. usage_msg    db    "usage: NE1000 [-n] [-d] [-w] <packet_int_no> <int_no> <io_addr>",CR,LF,'$'
  197.  
  198.     public    copyright_msg
  199. copyright_msg    db    "Packet driver for NE1000, version "
  200.         db    '0'+majver,".",'0'+version,".",'0'+dp8390_version,CR,LF,'$'
  201.  
  202. int_no_name    db    "Interrupt number ",'$'
  203. io_addr_name    db    "I/O port ",'$'
  204.  
  205.     extrn    set_recv_isr: near
  206.  
  207. ;enter with si -> argument string, di -> word to store.
  208. ;if there is no number, don't change the number.
  209.     extrn    get_number: near
  210.  
  211. ;enter with dx -> name of word, di -> dword to print.
  212.     extrn    print_number: near
  213.  
  214.     public    parse_args
  215. parse_args:
  216. ;exit with nc if all went well, cy otherwise.
  217.     mov    di,offset int_no
  218.     call    get_number
  219.     mov    di,offset io_addr
  220.     call    get_number
  221.     clc
  222.     ret
  223.  
  224.     extrn    etopen_diagn: byte
  225.  
  226. bad_addr_msg    label    byte
  227.  db "The Ethernet address of this card is invalid, because it has the",CR,LF
  228.  db "multicast bit set.  We will reset that bit and continue...",CR,LF,'$'
  229.  
  230. init_card:
  231. ;get the board data. This is (16) bytes starting at remote
  232. ;dma address 0. Put it in a buffer called board_data.
  233.  
  234.     mov    cx,10h        ; get 16 bytes,
  235.     push    ds
  236.     pop    es        ; set es to ds
  237.     mov    di,offset board_data
  238.     mov    ax,0        ; from address 0
  239.     call    sp_block_input
  240.  
  241.     push    ds              ; Copy from card's address to current address
  242.     pop     es
  243.  
  244.     test    board_data,1        ;did the fools pick their own id?
  245.     je    init_card_1        ;no.
  246.  
  247.     and    board_data,not 1    ;reset the multicast bit,
  248.     mov    dx,offset bad_addr_msg
  249.     mov    ah,9
  250.     int    21h
  251.  
  252. init_card_1:
  253.  
  254.     mov si, offset board_data    ; address is at start
  255.     mov di, offset curr_hw_addr
  256.     mov cx, EADDR_LEN       ; Copy one address length
  257.     rep     movsb           ; ..
  258.  
  259.     ret
  260.  
  261.     public    print_parameters
  262. print_parameters:
  263. ;echo our command-line parameters
  264.     mov    di,offset int_no
  265.     mov    dx,offset int_no_name
  266.     call    print_number
  267.     mov    di,offset io_addr
  268.     mov    dx,offset io_addr_name
  269.     call    print_number
  270.     ret
  271.  
  272. code    ends
  273.  
  274.     end
  275.